package org.example.controller;

import org.example.domain.entity.ProductImg;
import org.example.model.Result;
import org.example.service.ProductImgService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/img")
@CrossOrigin("*")
public class ProductImgController {
    @Resource
    private ProductImgService imgService;
    @GetMapping("/query")
    public Result queryImgById(@RequestParam Integer productId){
        return Result.buildSuccess(imgService.queryImages(productId));
    }
    @PostMapping("/update")
    public Result updateImg(@RequestBody ProductImg img){
        Boolean b = imgService.updateImage(img);
        if(b){
            return Result.buildSuccess(null);
        }else{
            return Result.buildFail("修改失败");
        }
    }
    @GetMapping("/delete")
    public Result deleteImg(@RequestParam Integer imgId){
        Boolean b = imgService.deleteImage(imgId);
        if(b){
            return Result.buildSuccess(null);
        }else{
            return Result.buildFail("删除失败");
        }
    }
    @PostMapping("/insert")
    public Result insertImg(@RequestBody ProductImg img){
        Boolean b = imgService.insertImage(img);
        if(b){
            return Result.buildSuccess(null);
        }else{
            return Result.buildFail("新增图片失败");
        }
    }
}
